package code;

public class IsPalindrome_day_07 {
    public static ListNode root;
    public static boolean flag=true;
    public static void main(String[] args) {
        ListNode head =null;
        root=head;
        isPalindrome_DFS(head);
        if(flag)System.out.println("Palindrome");
        else System.out.println("Not Palindrome");

    }
    public static class ListNode {
      int val;
      ListNode next;
      ListNode() {}
      ListNode(int val) { this.val = val; }
      ListNode(int val, ListNode next) { this.val = val; this.next = next; }
  }
//
    //递归可以闪现链表的逆序遍历
    //此时需要一个全局变量、做正序遍历的标志
    public static void isPalindrome_DFS(ListNode head) {
        if(head==null){
            return;
        }
        isPalindrome_DFS(head.next);
        if(head.val != root.val){
            flag=false;

        }
        root=root.next;
    }
}
